<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <script src="__STATIC__/js/common.js"></script>
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">信息管理</a>
        <a href="#">消息分类</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:window.location.reload();" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<xblock>
    <button class="layui-btn" id="typeAdd"><i class="layui-icon"></i>添加父类</button>
</xblock>
<table class="table table-bordered" >
    <tr>
        <th align="center" valign="middle" class="borderright">id号</th>
        <th align="center" valign="middle" class="borderright">父类名称</th>
        <th align="center" valign="middle" class="borderright">父id</th>
        <th align="center" valign="middle" class="borderright">路径</th>
        <th align="center" valign="middle">操作</th>
    </tr>
    {foreach($cateres as $val)}
    <tr id="del{$val.id}" >
        <?php
            $nbsp = substr_count($val['path'],",");
            $m = str_pad("",$nbsp*6*5,"&nbsp;");
        ?>
        <td >{$val.id}</td>
        <td >{$m}|--{$val.title}</td>
        <td >{$val.parent_id}</td>
        <td>{$val.path}</td>
        <td >
            <a href="/suggestion_type/add?pid={$val.id}&title={$val.title}&path={$val.path}{$val.id},"><button type="button" class="btn btn-primary btn-xs">添加子类</button></a>&nbsp;&nbsp;
            <a href="#"><button type="button" onclick="edit({$val.id})" class="btn btn-info btn-xs">编辑</button></a>&nbsp;&nbsp;
            <a href="#"><button type="button" onclick="del({$val.id})" class="btn btn-danger btn-xs">删除</button></a>
        </td>
     </tr>
    {/foreach}
</table>
</body>
<script>
    //添加父级
    $("#typeAdd").click(function(){
        window.location.href = "{:url('/suggestion_type/addPage')}";
    })
    //弹出编辑页面
    function edit(id) {
        layer.open({
            type:2,
            title:'编辑',
            area:['400px','200px'],
            content:"/suggestion_type/edit?id="+id
        });
    }
    //删除
    function del(id){
        layer.confirm('你确定要删除吗',{btn:['确定','取消']},function(){
            $.ajax({
                url:"{:url('/suggestion_type/typeDelete')}",
                data:{
                    id:id
                },
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            $("#del"+id).remove();
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    }
</script>
</html>